package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * 会员卡分录
 *
 * @author 文卡<wkwenka@gmail.com>  on 17-6-27.
 */
@Entity
@Table(name = "member_card_entry")
public class MemberCardEntry extends AbstractVersionEntity{

    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "owner_id")
    private MemberCard owner;

    @ManyToOne
    @JSONField(serialize = false)
    @JoinColumn(name = "goods_id")
    private Goods goods;

    @Size(min = 0, max = 100)
    private Integer rate; // 折扣率%

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", nullable = false, insertable = false, updatable = false)
    private Date createTime = new Date();

    private Integer state = Integer.valueOf(0);

    @Transient
    private String goodsPicturesName; //商品图片

    public MemberCard getOwner() {
        return owner;
    }

    public void setOwner(MemberCard owner) {
        this.owner = owner;
    }

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public Integer getRate() {
        return rate;
    }

    public void setRate(Integer rate) {
        this.rate = rate;
    }

    public String getGoodsPicturesName() {

        if (this.goodsPicturesName != null){
            return this.goodsPicturesName;
        }
        if (this.goods != null){
            return this.goods.getPictureName();
        }

        return goodsPicturesName;

    }

    public void setGoodsPicturesName(String goodsPicturesName) {
        this.goodsPicturesName = goodsPicturesName;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }
}
